<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>协作申请表添加-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">协作申请 > 协作申请表添加</div>
	</div>
	<div id="content">
		<form action="__APP__/Index/assist_apply_add" method="post" enctype="multipart/form-data">
			<input type="hidden" name="action" value="doadd">
			<div class="form-main">
				<div class="form-title">协作申请表添加</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>选择项目</div>
					<div class="input-item">
						<select name="pid" class="form-control required-selt w400" autocomplete="off">
							<option value="-10" selected>请选择</option>
							<foreach name="project_list" item="vo">
							<option value="{$vo['id']}">[{$vo['project_num']}]{$vo['project_name']}</option>
							</foreach>
						</select>
						<span class="error-item">必填项</span>
					</div>
				</div>
				<volist name="screen" id="vo" key="k">
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>{$vo['first_name']}</div>
						<div class="input-item">
							<if condition="$vo['property'] eq 1">
								<select name="types{$k}[val][]" class="form-control select-add" autocomplete="off">
									<option value="-10">请选择</option>
									<volist name="vo['second']" id="wo">
										<option value="{$wo['id']}">{$wo['second_name']}</option>
									</volist>
								</select>
								<!--input type="text" name="types{$k}[name]" class="form-control select-add-text ml5" autocomplete="off">
								<span class="error-item">必填项</span>
								<span class="error-item">该{$vo['first_name']}已存在</span-->
							<else/>
								<span class="mr10 checkbox-item">
									<volist name="vo['second']" id="wo">
										<label class="checkbox-inline"><input type="checkbox" value="{$wo['id']}" name="types{$k}[val][]" autocomplete="off">{$wo['second_name']}<if condition="($wo['times'] neq 0) and ($wo['times'] neq -1)">({$wo['times']})</if></label>
									</volist>
									<span class="error-item">必填项</span>
								</span>
								<!--input type="text" class="form-control label-add-text" autocomplete="off">
								<a href="javascript:;" first_id="{$vo['id']}" class="label-add-btn btn ml5">添加{$vo['first_name']}</a>
								<span class="error-item">请填写{$vo['first_name']}</span>
								<span class="error-item">请添加{$vo['first_name']}</span>
								<span class="error-item">该{$vo['first_name']}已存在</span-->
							</if>
							<input type="hidden" name="types{$k}[first_id]" value="{$vo['id']}">
						</div>
					</div>
				</volist>
				<div class="form-item">
					<div class="input-label">申请人</div>
					<div class="input-item">
						{$user['username']}
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">申请部门</div>
					<div class="input-item">
						{$user['position_descr']}
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">联系电话</div>
					<div class="input-item">
						{$user['mobilephone']}
					</div>
				</div>
				<div class="form-sub-title">申请需求内容</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>主要需求</div>
					<div class="input-item">
						<textarea name="main_demand" class="form-control w500 h150" autocomplete="off"></textarea>
						<input type="hidden" name="text_hid">
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">标准注释</div>
					<div class="input-item">
						<p>1、设计类，类似于设计风格，具体尺寸、数量等</p>
						<p>2、推广类，类似资源共享、推广策略方案、项目推广经验分享等</p>
						<p>4、策略类，类似于策略建议、方案优化建议、产品提升建议、短期协助驻场（7天内，特殊情况除外）等</p>
						<p>其他协作需求由于部门业务边界及权属问题，暂时不开展,,服务最终解释器</p>
					</div>
				</div>
				<div class="form-sub-title">提供介绍材料索引</div>
				<div class="editor_cont">
					<div class="form-item">
						<div class="input-label">上传资料</div>
						<div class="input-item">
							<div class="input-group w200 left mr10">
								<input type="text" name="file_name[]" class="form-control file-name" placeholder="请上传相关文档" readonly autocomplete="off">
								<span class="input-group-btn">
									<button class="btn file-submit" type="button">上传</button>
								</span>
							</div>
							<input type="hidden" name="file_url[]" class="file-url" autocomplete="off">
							<span class="error-item">文件名必填</span>
							<a href="javascript:;" class="data-add" data-toggle="tooltip" data-placement="bottom" title="生成"><i class="glyphicon glyphicon-plus"></i></a>
							<span class="error-item">请添加一个文件</span>
							<span class="error-item">请先上传此附件</span>
							<span class="error-item">文件名不能有“,”符号</span>
						</div>
					</div>
				</div>
			</div>
			<div class="form-btn-item"><button class="btn submit" type="submit">生成</button><button class="btn btn-default goback" type="button">返回</button></div>
		</form>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript">
$(function(){
	$("[name='main_demand']").each(function(){
		var textss = $(this).text(),
			reg2 = new RegExp("<br/>", "g"),
			str = textss.replace(reg2, "\n");
		$(this).html(str);
	})
	
	KindEditor.ready(function(K){
		//上传附件
		var editorFile = K.editor();
		$('.file-submit').on('click',function(){
			var parents = $(this).parents(".input-group");
			editorFile.loadPlugin('insertfile',function(){
				document.cookie="file_name=assist";
				document.cookie="file_type=ppt,pptx,pdf,doc,docx,jpg,jpeg,png,xls,xlsx,txt";
				editorFile.plugin.fileDialog({
					clickFn:function(url,title){
						parents.nextAll(".error-item").hide();
						parents.find(".file-name").val(title).prop("readonly",false);
						parents.nextAll(".file-url").val(url);
						parents.nextAll(".file-delete").show();
						editorFile.hideDialog();
					}
				});
			});
		});
	});
	
	//删除附件
	$(".file-delete").click(function(){
		$(this).hide();
		$(this).nextAll(".error-item").hide();
		$(this).nextAll(".file-url").val("");
		$(this).prevAll(".input-group").find(".file-name").val("").prop("readonly",true);
		$(this).parents("tr").find(".required-text2").next(".error-item").hide();
	});
	
	//添加资料
	$("body").on("click",".data-add",function(){
		$(this).siblings('.error-item').hide();
		var val = $(this).siblings('.input-group').find('.form-control').val();
		if((val=="" || /^\s+$/.test(val)) && !$(this).prop("readonly")){
			$(this).parent().find('.error-item').eq(2).show();
		}else{
			var tr = $(this).parents(".form-item"),
				cont = $('.editor_cont'),
				html = tr.clone(true);
			
			html.find(".tooltip,.input-group-btn").remove();
			html.find('.input-label').html('');
			tr.find(".error-item,.file-delete").hide();
			html.find(".file-delete").hide();
			tr.find(":text,:hidden").val("");
			tr.find(".file-name").prop("readonly",true);
			html.find(".data-add").replaceWith("<a href='javascript:;' class='data-delete mr10' data-toggle='tooltip' data-placement='bottom' title='删除'><i class='glyphicon glyphicon-trash'></i></a>");
			html.find(".data-delete,.data-add").tooltip({trigger:'hover'});
			cont.append(html);
		}
	});
	
	//删除资料
	$(document).on("click",".data-delete",function(){
		$(this).parents(".form-item").remove();
	});
	//文本域暂存
	$("[name='main_demand']").blur(function(){
		var val = $(this).val();
			reg = new RegExp("\n", "g"),
    		str = val.replace(reg, "<br/>");
		$("[name='text_hid']").val(str);
	})
	//提交验证
	$(".submit").click(function(){
		var tag = false;

		$("[name='pid']").each(function(){
			var val = $(this).val();
			if(val==-10){
				$(this).parent().find(".error-item").show();
				tag = true;
			}
		})
		$(".checkbox-item").each(function(){
			if($(this).find(":checkbox:checked").length==0){
				$(this).find(".error-item").show();
				tag = true;
			}
		});
		$("[name='remark']").each(function(){
			var val = $(this).val();
			if(val==''){
				$(this).next(".error-item").show();
				tag = true;
			}
		})
		$(".file-name").each(function(){
			var val = $(this).val();
			if((val=="" || /^\s+$/.test(val)) && !$(this).prop("readonly")){
				$(this).parents(".input-group").nextAll(".error-item").eq(0).show();
				tag = true;
			}
		});
		
		if(tag){
			return false;
		}
	});
	
	//隐藏错误提示
	$("[name='remark']").click(function(){
		$(this).next(".error-item").hide();
	})
	$('label').click(function(){
		$(this).parent().find(".error-item").hide();
	})
	$("[name='pid']").change(function(){
		$(this).parent().find(".error-item").hide();
	})
});
</script>
</body>
</html>